package com.zuosh.netty5;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * Created by kai on 2015/12/21 0021.
 */
public class myEncoder extends MessageToByteEncoder<String> {
    @Override
    protected void encode(ChannelHandlerContext ctx, String msg, ByteBuf out) throws Exception {
        System.out.println("msg will be encode...");
        out.writeBytes(msg.getBytes());
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        System.out.println("myEncoder#channel read...");
        ctx.fireChannelRead(msg);
    }

//    @Override
//    public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
//        System.out.println("myEncoder#channelRegistered ...");
//        ctx.fireChannelRead(this);
//    }
}
